#ifndef SysEvtHandler_First
#define SysEvtHandler_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Object.h"

class SeqCollection;

//---- SysEvtHandler -----------------------------------------------------------
//     abstract class for handling events from system resources

class SysEvtHandler : public Object {
public:
	MetaDef(SysEvtHandler);
	SysEvtHandler(int dummy);

	virtual void Remove();
#	define SafeRemove(p) { if (p) { p->Remove(); p= 0; } }

	virtual bool Notify();

protected:
	~SysEvtHandler();
};

//---- FileHandler -------------------------------------------------------------

class FileHandler : public SysEvtHandler {
public:
	MetaDef(FileHandler);
	FileHandler(int fd, int mask);
	int GetFd();
	void SetFd(int fd);
	virtual bool ReadNotify();
	virtual bool WriteNotify();
	virtual bool HasReadInterest();
	virtual bool HasWriteInterest();
	
protected:
	int fd, mask;
};

inline int FileHandler::GetFd()
	{ return fd; }
inline void FileHandler::SetFd(int f)
	{ fd= f; }

//---- Signals -----------------------------------------------------------------

enum Signals {
	eSigBus,
	eSigSegmentationViolation,
	eSigSystem,
	eSigPipe,
	eSigIllegalInstruction,
	eSigQuit,
	eSigInterrupt,
	eSigWindowChanged,
	eSigAlarm,
	eSigChild,
	eSigUrgent
};

//---- SignalHandler -----------------------------------------------------------

class SignalHandler : public SysEvtHandler {
public:
	MetaDef(SignalHandler);
	SignalHandler(Signals sig, bool sync= TRUE);
	Signals GetSignal();
	void SetSignal(Signals sig);
	bool IsSync();
	bool IsAsync();
	
protected:
	Signals sig;
	bool sync;
};

inline Signals SignalHandler::GetSignal()
	{ return sig; }
inline void SignalHandler::SetSignal(Signals s)
	{ sig= s; }
inline bool SignalHandler::IsSync()
	{ return sync; }
inline bool SignalHandler::IsAsync()
	{ return !sync; }

#endif
